package my.mark.mybaibaoxiang.juc.biji07.unsafe;

import java.util.concurrent.locks.LockSupport;

/**
 * @author wxming.
 * @description: 线程，阻塞、唤醒
 */
public class ThreadParkerTest {

    public static void main(String[] args) {

        /*Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("thread - is running----");
                LockSupport.park();//阻塞当前线程
                System.out.println("thread is over-----");
            }
        });

        t.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        LockSupport.unpark(t);//唤醒指定的线程*/

        //以下代码，如果先unpark再park，是不会阻塞的。相当于先拿票然后用。但是如果先park，没票便会阻塞当前线程。
        //拿出票据使用
        LockSupport.park();

        System.out.println("main thread is over");
        //相当于先往池子里放了一张票据
        LockSupport.unpark(Thread.currentThread());//park和unpark两个方法在Linux都是调的底层库Pthread_mutex

        System.out.println("im running step 1");
    }
}
